<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    
    </head>
    <body>
        <input type="button" value="添加行" onclick="addtr()">

        <table border="1" id="tid">
            <tr>
                <td>用户编号</td>
                <td>用户姓名</td>
                <td>操作</td>
            </tr>
            <tr>
                <td>1</td>
                <td>小明1</td>
                <td><input type="button" value="删除" onclick="delecttr(this)"></td>
            </tr>
            <tr>
                <td>2</td>
                <td>小明2</td>
                <td><input type="button" value="删除" onclick="delecttr(this)"></td>
            </tr>
        </table>
        <script>
                var j=3;
                function addtr(){
                    var tableobj =document.getElementById("tid");
                    var trobj =document.createElement("tr");
                    for (var i = 0; i < 2; i++) {
                        var tdobj = document.createElement("td");
                        tdobj.innerHTML=j++;
                        trobj.appendChild(tdobj);
                    }
                    var tdobj = document.createElement("td");
                    tdobj.innerHTML="<input type='button' value='删除' onclick=delecttr(this)>";
                    trobj.appendChild(tdobj);
                    tableobj.appendChild(trobj);
                }
        
                function delecttr(obj){
                var tr = obj.parentNode.parentNode;
                tr.parentNode.removeChild(tr);
                }
            </script>
    </body>
</html>
